home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / web / cweb.lha / cweb / examples / prod.web next >
Encoding:
Text File  |  1990-07-13  |  6.2 KB  |  125 lines

  1. \mathchardef\RA="3221 % right arrow
  2. \mathchardef\BA="3224 % double arrow
  3. Here is a table of all the productions.  Each production that
  4. combines two or more consecutive scraps implicitly inserts a {\tt \$}
  5. where necessary, that is, between scraps whose abutting boundaries
  6. have different |mathness|.  In this way we never get double {\tt\$\$}.
  7.  
  8. A translation is provided when the resulting scrap is not merely a
  9. juxtaposition of the scraps it comes from.  An asterisk* next to a scrap
  10. means that its first identifier gets an underlined entry in the index,
  11. via the function |make_underlined|.  Two asterisks** means that both
  12. |make_underlined| and |make_reserved| are called, that is, the
  13. identifier's ilk becomes |int_like|.  We use |in|, |out|, |back| and
  14. |bsp| as shorthands for |indent|, |outdent|, |backup| and
  15. |break_space|, respectively.
  16.  
  17. \def\tspan{\omit&&\omit\hfil\hskip-300pt}
  18. \def\alt #1 #2
  19. {$\displaystyle\Bigl\{\!\matrix{\hbox{#1}\cr\hbox{#2}\cr}\!\Bigr\}$ }
  20. \def\altt #1 #2 #3
  21. {$\displaystyle\Biggl\{\!\matrix{\hbox{#1}\cr\hbox{#2}\cr\hbox{#3}\cr}\!\Biggl\}$ }
  22. \def\malt #1 #2
  23. {$\displaystyle\matrix{\hbox{#1}\hfill\cr\hbox{#2}\hfill\cr}$}
  24. \def\maltt #1 #2 #3
  25. {$\displaystyle\matrix{\hbox{#1}\hfill\cr\hbox{#2}\hfill\cr\hbox{#3}\hfill\cr}$}
  26. {
  27. \yskip\newcount\prodno\prodno=0\def\ignore#1{}
  28. \halign to\hsize{\hfil\it\global\advance\prodno by1 \number\prodno\ignore{#}\ &%
  29. #\hfil\tabskip 0pt plus 200pt&%
  30. $\RA$ #\hfil&$\quad$#\hfil\tabskip0pt\cr
  31. \omit & LHS & RHS \hfill Translation & Example\cr
  32. \noalign{\yskip}
  33. & |exp| \alt|lbrace| |int_like| & |fn_decl| \alt|lbrace| |int_like| 
  34.     \hfill $F=E^*$ & \malt {|main(){|} {|main(argc,argv)int argc;|} \cr
  35. & |exp| |unop| & |exp| & |x++|\cr
  36. & |exp| \alt |binop| |unorbinop| |exp| & |exp| & \malt {|x+y|} {|x*y|} \cr
  37. & |exp| |comma| |exp| & |exp| \hfill $E_1C\,|opt|9\,E_2$& |f(x,y)|\cr
  38. & |exp| |exp| & |exp| & |time()|\cr
  39. & |exp| |semi| & |stmt| & |x=0;|\cr
  40. & |exp| |colon| & |tag| \hfill $E^*C$ & |found:|\cr
  41. & |lpar| |exp| |rpar| & |exp| & |(x+y)|\cr
  42. & |lpar| |rpar| & |exp| \hfill $L\.{\\,}R$ & functions and declarations\cr
  43. & |lpar| \alt |decl_head| |int_like| |rpar| & |cast| \hfill
  44.                             $LDR$ & |(char*)|\cr
  45. & |lpar| |stmt| & |lpar| \hfill $LS\.\ $ & |for| constructions\cr
  46. & |question| |exp| |colon| & |binop| & |x==y?x+1:0|\cr
  47. & |unop| |exp| & |exp| & |*x|\cr
  48. & |unorbinop| |exp| & |exp| \hfill $\.\{U\.\}$ & |*x|\cr
  49. & |unorbinop| |binop| & |binop| \hfill $|math_bin|\,U\.\{B\.\}\.\}$ & |*=|\cr
  50. & |binop| |binop| & |binop| \hfill
  51.             $B=|math_bin|\,B_1\.\{B_2\.\}\.\}$ & |x+=y|\cr
  52. & |cast| |exp| & |exp| \hfill $C\.\ E$ & |(double)x|\cr
  53. & |sizeof_like| |cast| & |exp| & |sizeof (double)|\cr
  54. & |sizeof_like| |exp| & |exp| \hfill $S\.\ E$ & |sizeof x|\cr
  55. & |int_like| \alt|int_like| |struct_like| &
  56.     \alt|int_like| |struct_like| \hfill $I\.\ $\alt $I$ $S$
  57.     \unskip& |extern char|\cr
  58. & |int_like| \alt|exp| |unorbinop| & |decl_head| 
  59.             \alt|exp| |unorbinop| \hfill $D=I\.\ $ & |int x|\cr
  60. & |decl_head| |comma| & |decl_head| \hfill $DC\.\ $ & |int x,y|\cr
  61. & |decl_head| |unorbinop| & |decl_head| \hfill $D\.\{U\.\}$ & |int *x|\cr
  62. & |decl_head| |exp| & |decl_head| \hfill $DE^*$ & |int x|\cr
  63. & |decl_head| \alt|binop| |colon| |exp| \alt|comma| |semi| &
  64.      |decl_head| \alt|comma| |semi| \quad
  65.      $D=D$\alt $B$ $C$ \unskip$E$ & \malt initialization fields \cr
  66. & |decl_head| \alt|int_like| |lbrace| & |fn_decl| 
  67.             \alt|int_like| |lbrace| & |long time () {|\cr
  68. & |decl_head| |semi| & |decl| & |int n;|\cr
  69. & |decl| |decl| & |decl| \hfill $D_1\,|force|\,D_2$ & |int n;double x;|\cr
  70. & |decl| \alt|stmt| |function| & \alt|stmt| |function| 
  71.     \hfill $D\,|big_force|\,$\alt $S$ $F$ \unskip& |extern n;main () {}|\cr
  72. & |typedef_like| |decl_head| |exp| & |typedef| |decl_head|
  73.                 \hfill $D=DE^{**}$ & |typedef char ASCII;|\cr
  74. & |typedef_like| |decl_head| |semi| & |decl| \hfill $T\.\ D$ &
  75.                             |typedef int x,y;|\cr
  76. & |struct_like| |lbrace| & |struct_head| \hfill $S\.\ L$ & |struct {|\cr
  77. & |struct_like| |exp| |lbrace| & |struct_head| \hfill $S\.\ E\.\ L$
  78.                         & |struct name_info {|\cr
  79. & |struct_like| |exp| & |int_like| \hfill $S\.\ E$ & |struct name_info z;|\cr
  80. & |struct_head| \alt|decl| |stmt| |rbrace| & |int_like|\cr
  81.     \tspan $S\,|in|\,|force|\,D\,|out|\,|force|\,R$ &
  82.                     |struct {| declaration |}|;\cr
  83. & |fn_decl| |decl| & |fn_decl| \hfill $F\,|force|\,D$ & |f(z) double z;| \cr
  84. & |fn_decl| |stmt| & |function| \hfill $F\,|force|\,S$ & |main ()| {\dots}\cr
  85. & |function| \alt |decl| |function| & \alt |decl| |function| \hfill
  86.   $F\,|big_force|\,$\alt $D$ $F$ & outer block\cr
  87. & |lbrace| |rbrace| & |stmt| \hfill $L\.{\\,}R$ & empty statement\cr
  88. & |lbrace| |stmt| |rbrace| & |stmt|\cr
  89.     \tspan $|force|\,L\,|in|\,|force|\,S\,
  90.         |force|\,|back|\,R\,|out|\,|force|$ & compound statement\cr
  91. & |lbrace| |exp| [|comma|] |rbrace| & |exp| & initializer\cr
  92. & |if_like| |exp| & |else_like| \hfill $I\.{\ }E$ & |if (z)|\cr
  93. & |else_like| |lbrace| & |if_head| |lbrace| & compound statement\cr
  94. & |else_like| |stmt| |else_like| & |else_like|\cr
  95. \tspan $|force|\,I\,|in|\,|bsp|\,S\,|out|\,|force|\,E\,|cancel|$ &
  96.                             |if|-|else| clause\cr
  97. & |else_like| |stmt| & |stmt|\cr
  98.   \tspan $|force|\,I\,|in|\,|bsp|\,S\,|out|\,|force|$ &
  99.                             |else|-less |if|\cr
  100. & |if_head| |stmt| |else_like| & |else_like|\cr
  101.   \tspan $|force|\,I\,|bsp|\,\.{\{\}}\,|cancel|\,S\,|bsp|\,E\,\.\ \,|cancel|$ &
  102.                             |if|-|else| clause\cr
  103. & |if_head| |stmt| & |stmt| \cr
  104.   \tspan $|force|\,I\,|bsp|\,\.{\{\}}\,|cancel|\,S\,|force|$
  105.                             & |else|-less |if|\cr
  106. & |do_like| |stmt| |if_like| & |if_like| \hfill 
  107.             $D\,|bsp|\,S\,|bsp|\,I$ & |do| statements\cr
  108. & |case_like| |semi| & |stmt| & |return;|\cr
  109. & |case_like| |exp| |semi| & |stmt| \hfill $R\.\ ES$ & |return 0;|\cr
  110. & |case_like| |colon| & |tag| & |default:|\cr
  111. & |case_like| |exp| |colon| & |tag| \hfill $C\.\ EC$ & |case 0:|\cr
  112. & |tag| |tag| & |tag| \hfill $T_1\,|bsp|\,T_2$ & |case 0: case 1:|\cr
  113. & |tag| |stmt| & |stmt| \hfill
  114.     $|force|\,|back|\,T\,|bsp|\,S$ & |case 0: z=0;|\cr
  115. & |stmt| |stmt| & |stmt| \hfill $S_1\,|bsp|\,S_2$ & compound statement\cr
  116. & |semi| & |stmt| & empty statement\cr
  117. & |lproc| \altt |if_like| |else_like| |define_like| & |lproc| &
  118.      \maltt {{\bf \#ifdef, \#include, \#line}} {\bf\#else} {\bf\#define} \cr
  119. & |lproc| |rproc| & |lrproc| & {\bf\#endif} \cr
  120. & |lproc| |exp| [|exp|] |rproc| & |lrproc| \hfill $I\.\ E{[\.\ E]}$ &
  121.                             |ifdef,include,line|\cr
  122. }
  123. }
  124.